package sfeir.gwt.ergosum.server.service;

import sfeir.gwt.ergosum.client.ClientApi.NotLoggedInException;
import sfeir.gwt.ergosum.client.model.Email;
import sfeir.gwt.ergosum.client.model.ImageURL;
import sfeir.gwt.ergosum.client.model.NetworkItem;
import sfeir.gwt.ergosum.client.model.Person;
import sfeir.gwt.ergosum.server.util.Pair;

import com.google.appengine.api.memcache.MemcacheService;
import com.google.appengine.api.memcache.MemcacheServiceFactory;
import com.google.inject.Singleton;

@Singleton
public class ProfileServiceMock implements ProfileService {

    private static final MemcacheService memcacheService = MemcacheServiceFactory.getMemcacheService();

    public ProfileServiceMock() {
        Person p = new Person();
        p.setFirstname("Florent");
        p.setName("Cappelle");
        p.setPhoto(new ImageURL("http://www.php-astux.info/images/tux-legende.png"));
        p.getEmails().add(new Email("cappelle.florent@gmail.com", Email.PERSONAL_EMAIL));
        p.getEmails().add(new Email("cappelle.f@sfeir.com", Email.PROFESSIONNAL_EMAIL));
        p.setCompany("SFEIR");
        p.setTitle("Stagiaire IT");
        p.setNickname("tux");
        p.getNetworkItems().add(
                new NetworkItem("facebook", "http://fr-fr.facebook.com/people/Florent-Cappelle/824359825"));
        memcacheService.put("florent@toto.com", p);
    }

    public Person getUserProfile() throws NotLoggedInException {
        throw new UnsupportedOperationException();
    }

    public Long savePerson(Person p) throws NotLoggedInException {
        memcacheService.put("florent@toto.com", p);
        return p.getId();
    }

    public void deleteCurrentProfile() throws NotLoggedInException {
        memcacheService.delete("florent@toto.com");
    }

    @Override
    public Person getProfile(String email) {
        return (Person) memcacheService.get("florent@toto.com");
    }

    @Override
    public String saveProfilePicture(String mime, byte[] data, String host) throws NotLoggedInException {
        throw new UnsupportedOperationException();
    }

    @Override
    public Pair<byte[], String> getProfilePicture(String email) {
        throw new UnsupportedOperationException();
    }
}
